package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：掌握释放资源的方式。
 */
public class Test2 {
    public static void main(String[] args)  {
        FileInputStream file1=null;
        FileOutputStream file2=null;
        try {
             file1 = new FileInputStream("D:\\Desktop\\1123.txt");
             file2 = new FileOutputStream("E:\\1123d\\112.txt");

            int len;
            byte[] buffer = new byte[1024];
            while ((len = file1.read(buffer)) != -1) {
                file2.write(buffer, 0, len);
            }

        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(file1!=null){
                try {
                    file1.close();
                }catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            if(file2!=null){
                try {
                    file2.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }

    }
}
